package com.cn.sl.server.api.system.menu.model.dto

import com.cn.sl.server.api.system.menu.model.entity.MenuEntity
import com.cn.sl.server.api.system.menu.model.enumerate.MenuType
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty

@Schema(description = "新增菜单")
data class AddMenuParam(
    /**
     * name
     */
    @field:NotBlank(message = "菜单名称不能为空")
    @field:Schema(description = "菜单名称")
    val name: String?,

    /**
     * path
     */
    @field:NotBlank(message = "Path不能为空")
    @field:Schema(description = "菜单路径")
    val path: String?,


    /**
     * 父级id
     */
    @field:Schema(description = "父级id")
    val parentId: Long?,

    /**
     * 组件
     */
    @field:Schema(description = "组件")
    val component: String?,

    /**
     * 重定向地址
     */
    @field:Schema(description = "重定向地址")
    val redirect: String?,

    /**
     * 扩展属性
     */
    @NotEmpty(message = "扩展属性不能为空")
    @field:Schema(description = "扩展属性")
    val meta: Map<String, Any>?,
) {
    fun toDto(): AddMenuDto {
        return AddMenuDto(
            name = name!!,
            path = path!!,
            parentId = parentId,
            component = component,
            redirect = redirect,
            type = MenuType.MENU,
            meta = meta!!
        )
    }
}

data class AddMenuDto(
    /**
     * name
     */
    val name: String,

    /**
     * path
     */
    val path: String,


    /**
     * 父级id
     */
    val parentId: Long?,

    /**
     * 组件
     */
    val component: String?,

    /**
     * 重定向地址
     */
    val redirect: String?,

    /**
     * 菜单类型
     */
    val type: MenuType,

    /**
     * 扩展属性
     */
    val meta: Map<String, Any>,
) {
    fun toEntity(): MenuEntity {
        val dto = this
        return MenuEntity().apply {
            this.name = dto.name
            this.path = dto.path
            this.parentId = dto.parentId
            this.component = dto.component
            this.redirect = dto.redirect
            this.type = dto.type
            this.meta = dto.meta
        }
    }
}